var exec = require('child_process').exec


function check(){
  const last = exec('lsof -i:3000');
  last.on('exit',function(code){
    if(code!= '0'){
      console.log(new Date().getTime()+"主服务已经关闭，正在重启");
      run()
    }else{
      console.log("==主服务正常运行==");
    }
  })
  setTimeout(check,5000)
}

function run(){
  const last = exec('node index.js')
  last.on('exit',function(code){
    if(code=='0'){
      console.log(new Date().getTime()+"主服务已重启成功");
    }else{
      console.log(new Date().getTime() + "主服务已重启失败***");
    }
  })
}

check()